package com.library.praise.service;

import com.library.entity.Book;
import com.library.entity.Evaluate;
import com.library.entity.Praise;
import com.library.entity.Staff;
import com.library.praise.dao.PraiseDaoImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(readOnly=false)
public class PraiseServiceImpl {
	
	@Resource
	private PraiseDaoImpl praiseDaoImpl;

	public void addPraise(Praise praise){
		this.praiseDaoImpl.savePraise(praise);
	}

    @Transactional(readOnly=true)
	public Praise getPraiseById(Integer priaseId)
	{
		return this.praiseDaoImpl.getPraiseById(priaseId);
	}

    @Transactional(readOnly=true)
	public List<Praise> getPraise(Staff s){
		return this.praiseDaoImpl.findByStaff(s);
	}

    @Transactional(readOnly=true)
    public List<Praise> getPraise(Evaluate evaluate){
		return this.praiseDaoImpl.findByEvaluate(evaluate);
    }

    @Transactional(readOnly = true)
	public Praise getPraise(Staff staff,Evaluate evaluate){
		return this.praiseDaoImpl.findByStaffAndEvaluate(staff,evaluate);
	}

	@Transactional(readOnly=true)
	public List<Praise> getPraise(Staff staff,Book book){
		return this.praiseDaoImpl.findByStaffAndBook(staff,book);
	}

	public void updatePraise(Praise praise){
		this.praiseDaoImpl.updatePraise(praise);
	}

    @Transactional(readOnly=true)
	/*查找全部评价记录*/
	public List<Praise> getAllPraise()
	{
		return this.praiseDaoImpl.getAll();
	}

	/*删除指定评价记录*/
	public void deletePraise(int praiseId){
		Praise p = this.getPraiseById(praiseId);
		this.praiseDaoImpl.deletePraise(p);
    }
}
